//
//  SXTTableViewController.m
//  10-10
//
//  Created by 钟纪旺 on 16/10/27.
//  Copyright © 2016年 zjw. All rights reserved.
//

#import "SXTTableViewController.h"
#import "MJRefresh.h"
@interface SXTTableViewController ()

@property (strong,nonatomic)NSMutableArray *dataArr;
@end

@implementation SXTTableViewController
static NSString * const cellId = @"cellID";
-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //下拉刷新
    self.tableView.mj_header = [MJRefreshStateHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    //上拉刷新
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    // 上啦刷新，开始刷新
    [self.tableView.mj_header beginRefreshing];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
//上拉刷新和 下拉刷新所响应的方法
-(void)loadNewData
{
    
    for (int i = 0; i<10; i++) {
        int x = arc4random() % 1000;
        NSNumber *num = [NSNumber numberWithInt:x];
        
        if ([self.dataArr containsObject:num]) {
            continue;
        }
        [self.dataArr addObject:num];
        
    }
    
    [self.tableView reloadData];
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
